home *** CD-ROM | disk | FTP | other *** search
- head 1.1;
- branch 1.1.1;
- access ;
- symbols start:1.1.1.1 oleg:1.1.1;
- locks ; strict;
- comment @// @;
-
-
- 1.1
- date 2005.01.09.18.45.06; author oleg; state Exp;
- branches 1.1.1.1;
- next ;
-
- 1.1.1.1
- date 2005.01.09.18.45.06; author oleg; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @//
- // AppInfo.m
- // RocketLauncher
- //
- // Created by Oleg Kibirev on 12/31/04.
- // Copyright 2004 My Stuff. All rights reserved.
- //
-
- #import "AppInfo.h"
- #import <unistd.h>
- #import <sys/stat.h>
-
-
- @@implementation AppInfo
-
- -(NSString *)fullPath {
- return [[NSWorkspace sharedWorkspace] fullPathForApplication:name];
- }
-
- -(id)initWithName: (NSString *)n path: (NSString *)p isOSX: (BOOL)osx {
- self = [super init];
- name = [n retain];
- path = [p retain];
- isOSX = osx;
- return self;
- }
-
- -(void)copyFrom: (AppInfo *)ai {
- [name autorelease]; name = [ai->name retain];
- [path autorelease]; path = [ai->path retain];
- [icon autorelease]; icon = [ai->icon retain];
- isOSX = ai->isOSX;
- gotIcon = ai->gotIcon;
- }
-
- -(void)dealloc {
- [name release];
- [icon release];
- [path release];
- [super dealloc];
- }
-
- -(NSString *)name { return name; }
- -(NSImage *)icon {
- if (!gotIcon) {
- icon = [[[NSWorkspace sharedWorkspace] iconForFile:path] retain];
- gotIcon = YES;
- }
- return icon;
- }
-
- -(NSComparisonResult)compare: (AppInfo *)ai {
- return [name compare: [ai name]];
- }
-
- -(BOOL)launch {
- NSWorkspace *ws = [NSWorkspace sharedWorkspace];
- return [ws launchApplication:path] || [ws launchApplication:name];
- }
-
- static char *clgets(char *buf, size_t len, FILE *fin) {
- buf[len-1] = '\0';
- if (!fgets(buf, len-1, fin)) return NULL;
- len = strlen(buf);
- if (len && buf[len-1] == '\n')
- buf[len-1] = '\0';
- return buf;
- }
-
- BOOL hasSubstr(const char *s1, const char *s2) {
- NSRange r = [[NSString stringWithUTF8String:s1] rangeOfString:[NSString stringWithUTF8String:s2] options: NSCaseInsensitiveSearch];
- return r.location != NSNotFound;
- }
-
- +(NSArray *)allApps: (NSArray *)oldList {
- NSMutableArray *ma = [NSMutableArray arrayWithCapacity:100];
- // Is there a programmatic way to do this?
- FILE *appList = popen("/System/Library/Frameworks/ApplicationServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump", "r");
- char buf[4096];
- NSMutableDictionary *oldApps = [NSMutableDictionary dictionaryWithCapacity:100];
- if (oldList != nil) {
- int i;
- for (i = 0; i < [oldList count]; i++) {
- AppInfo *ai = [oldList objectAtIndex:i];
- [oldApps setObject:ai forKey:[ai name]];
- }
- }
- if (appList) {
- NSMutableDictionary *appSet = [NSMutableDictionary dictionaryWithCapacity:100];
- while (clgets(buf, sizeof(buf), appList)) {
- if (buf[0] != 'B') continue;
- mainLoop:;
- size_t end = strlen(buf)-1;
- if (end >= 4 && !strcasecmp(buf+end-3, ".app")) {
- end-=4;
- buf[end+1] = '\0';
- }
- while (end >= 2 && (buf[end-1] != ' ' || buf[end-2] != ' '))
- end--;
- if (end < 2) continue;
- NSString *appName = [NSString stringWithUTF8String:buf+end];
- NSString *appPath = nil;
- if (!appName) continue;
- if ([appName isEqual: @@"RocketLauncher"]) continue;
- int lineNo;
- BOOL osx;
- for (lineNo = 0; lineNo < 10 && clgets(buf, sizeof(buf), appList); lineNo++) {
- char *p = buf;
- while (*p && isspace(*p)) p++;
- if (p[0] == 'B') goto mainLoop;
- if (*p == 'V' && isdigit(p[1])) {
- while (!isspace(*p)) p++;
- while (*p && isspace(*p)) p++;
- // Filter out system apps
- if (!strncasecmp(p, "/System/", sizeof("/System/")-1))
- continue;
- if (hasSubstr(p, "/System Folder/"))
- continue;
- #if 0
- if (hasSubstr(p, "/Applications (Mac OS 9)/"))
- continue;
- #endif
- if (hasSubstr(p, ".exe ")) // Virtual PC wrappers
- continue;
- struct stat st;
- if (stat(p, &st) == -1)
- continue;
- if(S_ISDIR(st.st_mode)) {
- // Check if a valid bundle
- NSString *p1 = [[[NSString stringWithUTF8String:p] stringByAppendingPathComponent:@@"Contents"] stringByAppendingPathComponent: @@"Info.plist"];
- if (access([p1 UTF8String], R_OK) == -1)
- continue;
- osx = YES;
- } else
- osx = NO;
- appPath = [NSString stringWithUTF8String:p];
- break;
- }
- }
- if (!appPath) continue;
- AppInfo *ai = [appSet objectForKey:appName];
- AppInfo *nai = [[[AppInfo alloc] initWithName:appName path:appPath isOSX: osx] autorelease];
- AppInfo *oldAI = [oldApps objectForKey:appName];
- if (oldAI && [oldAI->path isEqual:nai->path] && oldAI->icon && !nai->icon)
- nai = oldAI;
- if (!ai) {
- [appSet setObject:nai forKey:appName];
- [ma addObject:nai];
- } else if (([ai icon] == nil && [nai icon] != nil) || (nai->isOSX && !ai->isOSX))
- [ai copyFrom:nai];
- }
- pclose(appList);
- }
- [ma sortUsingSelector:@@selector(compare:)];
- return ma;
- }
- @@end
- @
-
-
- 1.1.1.1
- log
- @RocketLauncher
- @
- text
- @@
-